from dataclasses import dataclass
from typing import List
from enum import Enum

# 定义基础枚举类型
class Direction(Enum):
    STRAIGHT = "直行"
    LEFT = "左转"
    RIGHT = "右转"

class TrafficLightStatus(Enum):
    RED = "红灯"
    GREEN = "绿灯"
    YELLOW = "黄灯"

# 数据类定义
@dataclass
class Position:
    x: int
    y: int

    def __eq__(self, other):
        if other is None:
            return False
        # 如果比较对象不是Position类型，直接返回False
        if not isinstance(other, Position):
            return False
        return self.x == other.x and self.y == other.y

    def __hash__(self):
        return hash((self.x, self.y))
    
    def __lt__(self, other):
        # 首先比较x坐标，如果相等则比较y坐标
        if self.x == other.x:
            return self.y < other.y
        return self.x < other.x

@dataclass
class Vehicle:
    id: str
    current_position: Position
    destination: Position
    route: List[Position] = None
    speed: float = 1.0  # 每次更新移动的距离
    current_route_index: int = 0  # 当前在路径中的位置索引
    
    # 添加用于平滑移动的属性
    screen_x: float = 0.0  # 屏幕上的实际x坐标
    screen_y: float = 0.0  # 屏幕上的实际y坐标
    moving: bool = False   # 是否正在移动
    
    def __eq__(self, other):
        return self.id == other.id 